package com.wayne.leetcode.problems;

public class Solution14 {
  public static String longestCommonPrefix(String[] strs) {
    StringBuilder prefix = new StringBuilder();
    int start = 0;
    end:
    while (strs[0].length() > start) {
      String tmp = strs[0].substring(0, start + 1);
      for (String str : strs) {
        if (!str.startsWith(tmp)) {
          break end;
        }
      }
      start++;
      prefix.append(tmp.substring(tmp.length() - 1));
    }
    return prefix.toString();
  }

  public static void main(String[] args) {
    System.out.println(longestCommonPrefix(new String[]{"find", "fiund", "fiiend"}));
  }
}